package com.merry.spring5.resource;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.io.Resource;


/**
 * @author ybzou
 */
@Configuration
@ComponentScan(value = "com.merry.spring5.resource")
@PropertySource(value = {"classpath:resource.properties"})
public class ResourceConfig {
    @Value("${resource.path}")
    private String resourcePath;

   @Bean
    public ResourceBean resourceBean(ApplicationContext applicationContext){
        ResourceBean resourceBean = new ResourceBean();
        Resource resource = applicationContext.getResource(resourcePath);
        resourceBean.setResource(resource);
        return resourceBean;
    }
}
